package com.qing.spark.dao

import java.sql.{Connection, DriverManager}

/**
  * Created by wuliao on 2018/3/26.
  */
class MysqlUtils {
  //声明Connection对象
  val driver = "com.mysql.jdbc.Driver"
  val url = "jdbc:mysql://175.102.18.112:3306/sflow"

  val user = "root"
  val password = "new.123"

  Class.forName(driver)
  var con = DriverManager.getConnection(url, user, password)

  def getCon(): Connection = {
    con
  }

  def reCon(): Unit = {
    if (con == null || con.isClosed) {
      con = DriverManager.getConnection(url, user, password)
    }
  }
}

object MysqlUtils {
  private var instance: MysqlUtils = null

  def getInstance: MysqlUtils = {
    if (null == instance)
      instance = new MysqlUtils
    instance
  }
}
